<?php
/**
 * Created by PhpStorm.
 * User: 刘红波 <liuhb@cqjcdflzxsws.com>
 * Date: 2018/10/22
 * Time: 16:28
 */

namespace app\api\model;


use think\Model;

class WeReport extends Model
{
    protected $autoWriteTimestamp = true;

    public function reportTopic($data)
    {
        $data['type'] = 1;
        $res = self::create($data);
        if (!$res){
            return false;
        }else{
            return $res;
        }
    }


    public function reportDetail($data)
    {
        $data['type'] = 2;
        $res = self::create($data);
        if (!$res){
            return false;
        }else{
            return true;
        }
    }


    /**
     * 判断是否已经举报过同一条信息
     * @param $data
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function alreadyReport($data)
    {
        $res = self::where(['type' => 1, 'user_id' => $data['user_id'], 'value' => $data['value']])->find();
        if (!$res){
            return false;
        }else{
            return true;
        }
    }
}